package com.rmt.www.serviceImpl;

import com.opensymphony.xwork2.ActionContext;
import com.rmt.www.service.DevManageDesignService;
import com.rmt.www.constant.ArtifactStatus;
import com.rmt.www.constant.RequestType;
import com.rmt.www.dao.*;
import com.rmt.www.utility.SystemTime;
import com.rmt.www.vo.DesignArtifact;
import com.rmt.www.vo.DesignArtifactRequest;
import com.rmt.www.vo.User;

public class DevManageDesignServiceImpl implements DevManageDesignService {

	private DesignArtifactRequestDao designArtifactRequestDao;
	private DesignArtifactDao designArtifactDao;
	private UserDao userDao;
	
	public DesignArtifactRequestDao getDesignArtifactRequestDao() {
		return designArtifactRequestDao;
	}

	public void setDesignArtifactRequestDao(
			DesignArtifactRequestDao designArtifactRequestDao) {
		this.designArtifactRequestDao = designArtifactRequestDao;
	}

	public DesignArtifactDao getDesignArtifactDao() {
		return designArtifactDao;
	}

	public void setDesignArtifactDao(DesignArtifactDao designArtifactDao) {
		this.designArtifactDao = designArtifactDao;
	}

	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	public void addNewDesignRequest(DesignArtifactRequest request) {
		designArtifactRequestDao.insertDesignArtifactRequest(request);
	}

	public void deleteDesign(int id) {
		DesignArtifact a = designArtifactDao.getDesignArtifactById(id);
		DesignArtifactRequest r = new DesignArtifactRequest();
		r.setPid(a.getPid());
		r.setTitle(a.getTitle());
		r.setDesignartifactid(a.getId());
		r.setPriority(a.getPriority());
		r.setEffort(a.getEffort());
		r.setCost(a.getCost());
		r.setRisk(a.getRisk());
		r.setComment(a.getComment());
		r.setUpdatedtimes(a.getUpdatedtimes());
		r.setVersion(a.getVersion());
		r.setStatus(a.getStatus());
		r.setConsideration(a.getConsideration());
		r.setInput(a.getInput());
		r.setFunction(a.getFunction());
		r.setOutput(a.getOutput());
		r.setPerfrequest(a.getPerfrequest());
		r.setSecurityrequest(a.getSecurityrequest());
		r.setStoragerequest(a.getStoragerequest());
		r.setInnerinterface(a.getInnerinterface());
		r.setOuterinterface(a.getOuterinterface());
		r.setCreaterid(a.getCreaterid());
		r.setCreatedtime(a.getCreatedtime());
		r.setArchitect(a.getArchitect());
		
	 	r.setUpdatedtime(new java.sql.Timestamp(SystemTime.getSystemTime().getTime()));
	 	r.setRequesttype(RequestType.DELETE);
		User u=(User)ActionContext.getContext().getSession().get("currentUser");
		r.setUpdaterid(u.getUid());
		designArtifactRequestDao.insertDesignArtifactRequest(r);
	}

	public void updateDesign(DesignArtifactRequest request) {
		
	}

	public DesignArtifact getDesignArtifact(int id) {
 		DesignArtifact a = designArtifactDao.getDesignArtifactById(id);
 		a.set_authorname(userDao.getUser(a.getCreaterid()).getName());
 		a.set_updatername(userDao.getUser(a.getUpdaterid()).getName());
 		return a;
	}

}
